<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:cs="http://myfaces.apress.com/custom"
	template="/WEB-INF/layouts/standard.xhtml" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
	xmlns:bf="http://www.bssmanager.com/jsf" xmlns:c="http://java.sun.com/jstl/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

	<ui:define name="headIncludes">
		<script>
			function checkOutConfirmation(pn) {
				return showConfirmation("Please make a note that you need to refund "+									
									"\nSecurity Deposit and Utensil Deposit " +
									"\nafter clicking the OK button to complete the process !"+
									"\nAre you sure to start the check-out for the patient "+pn+" ? ");
			}				
		</script>
	</ui:define>
	
	<ui:define name="formheader">
		<h2>Check Out</h2>
	</ui:define>
	
	<ui:define name="formGlobal">
		<bf:dateSelector controller="#{admissionController}"  date="exitDate" ajaxUpdate="false"/>
	</ui:define>
	
	<ui:define name="content">
		<h:form id="exitForm">
			<a4j:status forceId="true" id="chkout">
							<f:facet name="start">
								<h:graphicImage value="/images/im1.gif" />
							</f:facet>
						</a4j:status>
		
		<h:panelGrid columns="1">

						<rich:dataTable value="#{admissionController.exitableAdmissions}" var="aBean" align="left" id="chkPat">
							<f:facet name="header">
								<h:outputText value="Patients ready for Checkout" />
							</f:facet>
							<rich:column>
								<f:facet name="header">ID</f:facet>
								<h:outputText value="#{aBean.id}" />
							</rich:column>
							<rich:column>
								<f:facet name="header">
									<h:outputText value="Check Out" styleClass="norender"/>
								</f:facet>
								
										<a4j:commandButton rendered="#{not aBean.exitInited}"
											onclick="if(!checkOutConfirmation('#{aBean.patient.firstName} #{aBean.patient.lastName} #{aBean.patient.middleName}')) return false;"
											title="Click to start check out"
											image="/images/log-out.png"
											style="width:30px;height:37px;" status="chkout" 
											reRender="chkPat"
											oncomplete="if(#{admissionController.error})alert('Error: #{admissionController.errors[0]}');else { alert('Checkout Process Started Successfully ! \nPlease proceed to refund the Security Deposit and Utensil Deposit.\nYou may also make any donations');  document.location.href='payment.jsf?operation=refund&amp;admissionId=#{aBean.id}'; }"
											action="#{admissionController.startCheckout}" styleClass="norender" />
									
									<h:panelGroup rendered="#{aBean.exitInited}">
										<div> 
											Started											
										</div>
										<div>
											<a href="#" onclick="document.location.href='payment.jsf?admissionId=#{aBean.id}&amp;operation=refund'" title="Checkout will be complete when all deposits are refunded and rents recovered">Complete</a>
										</div>
									</h:panelGroup>
							</rich:column>																								
							<rich:column>
								<f:facet name="header">Name</f:facet>
								<h:outputText value="#{aBean.patient.firstName} #{aBean.patient.lastName} #{aBean.patient.middleName} " />
							</rich:column>
							<rich:column>
								<f:facet name="header">CheckIn Date</f:facet>
								<h:outputText value="#{aBean.dateOfAdmission}">
									<f:convertDateTime pattern="dd MMM yyyy HH:mm" />
								</h:outputText>
							</rich:column>
							<rich:column>
								<f:facet name="header">Rooms</f:facet>
								<h:outputText value="#{aBean.roomBookings}"/>								
							</rich:column>
							<rich:column>
								<f:facet name="header">Beds</f:facet>							
								<h:outputText value="#{aBean.bedBookings}"/>
							</rich:column>							
							<rich:column>
								<f:facet name="header">Utensil Set</f:facet>
								<h:outputText value="#{aBean.materialSet}" converter="#{materialSetConverter}" />
								<h:outputText value="(Rs #{aBean.materialSet.deposit})"/>
							</rich:column>
							<rich:column style="text-align:center">
								<f:facet name="header">Photograph</f:facet>
								<h:graphicImage width="50" height="37" url="/bss/images/saved?id=#{aBean.patient.id}" onmouseout="hideLarge()"
									style="border-width: 1px; border-style:solid; border-color:black;"
									onmouseover="showLarge(event,this,'#{request.contextPath}/bss/images/saved?id=#{aBean.patient.id}');" />
							</rich:column>
							<f:facet name="footer">
								<h:outputText value="Total (#{admissionController.exitableAdmissions.rowCount}) Patients available for Check-Out" />
							</f:facet>
						</rich:dataTable>
			
			
			<rich:dataTable value="#{admissionController.exitedAdmissions}" var="aBean" id="exitedAdmissions">
							<f:facet name="header">
								<h:outputText value="Checked-Out Patients" />
							</f:facet>
							<rich:column>
								<f:facet name="header">ID</f:facet>
								<h:outputText value="#{aBean.id}" />
							</rich:column>																													
							<rich:column>
								<f:facet name="header">Name</f:facet>
								<h:outputText value="#{aBean.patient.firstName} #{aBean.patient.lastName} #{aBean.patient.middleName} " />
							</rich:column>
							<rich:column>
								<f:facet name="header">CheckIn Date</f:facet>
								<h:outputText value="#{aBean.dateOfAdmission}">
									<f:convertDateTime pattern="dd MMM yyyy HH:mm" />
								</h:outputText>
							</rich:column>
							<rich:column>
								<f:facet name="header">CheckOut Date</f:facet>
								<h:outputText value="#{aBean.dateOfExit}">
									<f:convertDateTime pattern="dd MMM yyyy HH:mm" timeZone="#{userService.timeZoneID}" />
								</h:outputText>
							</rich:column>														
							<f:facet name="footer">
								<h:outputText value="Total (#{admissionController.exitedAdmissions.rowCount}) Patients already Checked-Out" />
							</f:facet>
						</rich:dataTable>
						
	</h:panelGrid>						

			<img id="imageEnlarged" src="" width="320" height="240" alt="No Image"
				style="position: absolute; visibility: hidden; border-width: 2px; border-style: solid; border-color: red;" />
									

		</h:form>
		
		
	</ui:define>
</ui:composition>